{% extends 'index.html' %}

{% block page-title %}

下载地址切换

{% endblock %}

{% block page-content %}
<style>
.mask {
        position: absolute; top: 0px; filter: alpha(opacity=60); background-color: #777;
        z-index: 1002; left: 0px;
        opacity:0.5; -moz-opacity:0.5;
}
#table-1 thead, #table-1 tr {
border-top-width: 1px;
border-top-style: solid;
border-top-color: rgb(230, 189, 189);
}
#table-1 {
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: rgb(230, 189, 189);
}

/* Padding and font style */
#table-1 td, #table-1 th {
padding: 5px 10px;
font-size: 12px;
font-family: Verdana;
color: rgb(177, 106, 104);
}

/* Alternating background colors */
#table-1 tr:nth-child(even) {
background: rgb(238, 211, 210)
}
#table-1 tr:nth-child(odd) {
background: #FFF
}

</style>
    <div style="font-size:20px">地址格式：http://qqrjtu.xy1758.com<span style="color:deepskyblue;font-size:20px">/mirrors/ylmf/9010/windows_7_ultimate_x64_YL_2018.iso</span></div>
    <div style="font-size:20px;color:rebeccapurple">注意：蓝色标注的就是地址格式！！！</div>
<div>
    <table class="table" id="table-1">
        <tr>
            <th>编号</th>
            <th>地址标识</th>
            <th>新地址</th>
            <th>操作</th>
        </tr>
        {% for download in download_list %}
        <tr>
            <td>{{ download.id }}</td>
            <td>{{ download.name }}</td>
            <td><input type="text" name="new_download" size="135"/></td>
            <td><button class="btn btn-primary btn-sm" onclick="confirmAct(this)">切换</button></td>
        </tr>
        {% endfor %}
    </table>
</div>
<div id="mask" class="mask"></div>
<script type="text/javascript">

function download_switch(ele){
    var html_ele=ele;
    var id=$(html_ele).parent().prev().prev().prev().text();
    var new_download=$(html_ele).parent().prev().children().val();
    $.ajax({
        url: '/download_switch/',
        type: 'post',
        data: {id:id,new_download:new_download},
        async: true,
        success: function (callback) {
            //console.log(callback);
            hideMask();
            callback=JSON.parse(callback);
            console.log(callback['status']);
            if(callback['status']=='0'){
                alert('下载地址切换成功！请记得切换迅雷下载');
                $(html_ele).parent().prev().children().val('');
            }else{
                alert(callback['result']);
            }

        }
    })
}
function showMask(){
    $("#mask").css("height",$(document).height());
    $("#mask").css("width",$(document).width());
    $("#mask").show();
}
//隐藏遮罩层
function hideMask(){

    $("#mask").hide();
}

function confirmAct(ele){
    var html_ele=ele;
    var id=$(html_ele).parent().prev().prev().prev().text();
    var new_download=$(html_ele).parent().prev().children().val();
    var address_name=$(html_ele).parent().prev().prev().text();
    if (new_download == '') {//判断校检是否通过
         alert("新地址不能为空！");
        //return;
    }else {

        if (confirm('你现在修改的是'+address_name+',确定吗？')){
            showMask();
            return download_switch(ele);
        }

    }
}

</script>
{% endblock %}
